﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.WeChatOfficialAccount.DAL;
using XQ.WeChatOfficialAccount.DAL.DAL;

namespace XQ.WeChatOfficialAccount.BLL.Sys
{
    public class UploadBLL
    {
        private UploadDal uploadDal = new UploadDal();

        /// <summary>
        /// 保存上传
        /// </summary>
        /// <param name="uploads"></param>
        /// <param name="studentID"></param>
        /// <returns></returns>
        public bool SaveUpload(List<Upload> uploads, int businessID, string tableName, string signName)
        {
            //删除旧的上传关联
            uploadDal.DeleteModel(u =>u.businessID== businessID && u.signName == signName && u.tableName == tableName);
            if (uploads != null && uploads.Count > 0)
            {
                //保存新的上传
                return uploadDal.AddModels(uploads) > 0;
            }
            return false;
        }

        /// <summary>
        /// 获取指定的上传列表
        /// </summary>
        /// <param name="uploads"></param>
        /// <returns></returns>
        public List<Upload> GetUpload(string tableName, string signName, int businessID)
        {
            return uploadDal.FindAllModel(u => u.tableName == tableName && u.signName == signName && u.businessID == businessID);
        }

        /// <summary>
        /// 删除指定条件的上传记录
        /// </summary>
        /// <param name="uploads"></param>
        /// <returns></returns>
        public bool DeleteUpload(string tableName, string signName, int businessID)
        {
            return uploadDal.DeleteModel(u => u.tableName == tableName && u.signName == signName && u.businessID == businessID) > 0;
        }
    }
}
